//
//  SearchTypeFirlterView.m
//  YJRenter
//
//  Created by 文彬 on 2018/7/13.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "SearchTypeFirlterView.h"

@interface SearchTypeFirlterView()

@property (weak, nonatomic) UIButton *selectBtn;
@end

@implementation SearchTypeFirlterView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self initControl];
    }
    return self;
}

- (void)initControl{
    
    self.backgroundColor = RGBACOLOR(0, 0, 0, 0.5);
    
    UIView *middleView = [[UIView alloc]init];
    middleView.layer.cornerRadius = 5;
    middleView.backgroundColor = [UIColor whiteColor];
    [self addSubview:middleView];
    [middleView makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@300);
        make.height.equalTo(@250);
        make.centerX.equalTo(self.centerX);
        make.centerY.equalTo(self.centerY);
    }];
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeBtn setBackgroundImage:[UIImage imageNamed:@"CheckSelected"] forState:UIControlStateNormal];
    [self addSubview:closeBtn];
    [closeBtn makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(@30);
        make.centerX.equalTo(middleView.right);
        make.centerY.equalTo(middleView.top);
    }];
    [closeBtn buttonClick:^{
        [self removeFromSuperview];
    }];
    
    UILabel *messLabel = [[UILabel alloc]init];
    messLabel.text = @"类型选择";
    messLabel.font = [UIFont systemFontOfSize:15];
    messLabel.textColor = kTitleColor;
    [middleView addSubview:messLabel];
    [messLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@15);
        make.top.equalTo(@20);
        make.height.equalTo(@25);
        make.width.equalTo(@100);
    }];
    
    NSArray *titles = @[@"时租",@"短租",@"旅居",@"特卖",@"意拍"];
    for (int i=0; i<2; i++) {
        for (int j=0; j<3; j++) {
            if (i==1&&j==2) {
                break;
            }
            int tag = i*3+j;
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setTitle:titles[tag] forState:UIControlStateNormal];
            [button setTitleColor:kTitleColor forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:15];
            button.layer.borderColor = kSecTitleColor.CGColor;
            button.layer.borderWidth = 0.5;
            button.layer.cornerRadius = 3;
            [middleView addSubview:button];
            [button makeConstraints:^(MASConstraintMaker *make) {
                make.width.equalTo(@70);
                make.height.equalTo(@40);
                make.left.equalTo(@(25+j*(70+20)));
                make.top.equalTo(@(60+i*(40+20)));
            }];
            [button buttonClick:^{
               
                [self setButtonUnSelectStyle:self.selectBtn];
                
                self.selectBtn = button;
                 [self setButtonSelectStyle:button];
                
            }];
            
            if (i==0&&j==0) {
                self.selectBtn = button;
                [self setButtonSelectStyle:button];
            }
        }
    }
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"确定" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    button.backgroundColor = kMainOriginColor;
    button.layer.cornerRadius = 3;
    [middleView addSubview:button];
    [button makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@150);
        make.height.equalTo(@40);
        make.centerX.equalTo(middleView.centerX);
        make.bottom.equalTo(@-20);
    }];
    [button buttonClick:^{
        [self removeFromSuperview];
    }];
}

- (void)setButtonSelectStyle:(UIButton*)button{
    button.backgroundColor = kMainOriginColor;
    button.layer.borderColor = [UIColor clearColor].CGColor;
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}

- (void)setButtonUnSelectStyle:(UIButton*)button{
    self.selectBtn.layer.borderColor = kSecTitleColor.CGColor;
    self.selectBtn.backgroundColor = [UIColor clearColor];
    [self.selectBtn setTitleColor:kTitleColor forState:UIControlStateNormal];
}

@end
